package com.system.presideover.controller;


import com.system.common.result.Result;
import com.system.presideover.entity.ContactNumber;
import com.system.presideover.service.ContactNumberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 联系电话 前端控制器
 * </p>
 *
 * @author system
 * @since 2024-04-16
 */
@Api(tags = "联系电话")
@RestController
@RequestMapping("/presideover/contact-number")
public class ContactNumberController {

    @Autowired
    private ContactNumberService contactNumberService;

    @ApiOperation(value = "联系电话")
    @GetMapping("/listContactNumber")
    public Result listContactNumber(){
        List<ContactNumber> list = contactNumberService.list();
        return Result.ok(list);
    }

    @ApiOperation(value = "添加联系电话")
    @PostMapping("/saveContactNumber")
    public Result saveContactNumber(@RequestBody ContactNumber accountNumber){
        boolean save = contactNumberService.save(accountNumber);

        if (save){
            return Result.ok().message("添加成功");
        }
        return Result.fail().message("添加失败");
    }


    @ApiOperation(value = "修改联系电话")
    @PostMapping("/updateContactNumber")
    public Result updateContactNumber(@RequestBody ContactNumber accountNumber){
        boolean save = contactNumberService.updateById(accountNumber);

        if (save){
            return Result.ok().message("修改成功");
        }
        return Result.fail().message("修改失败");
    }

    @ApiOperation(value = "删除联系电话")
    @PostMapping("/delectContactNumber")
    public Result delectContactNumber(@RequestBody ContactNumber accountNumber){
        boolean save = contactNumberService.removeById(accountNumber.getId());

        if (save){
            return Result.ok().message("删除成功");
        }
        return Result.fail().message("删除失败");
    }
}

